<?php

global $facebook;

// set page id
$pageid = 'cibertechworldservices';

// now we can access various parts of the graph, starting with the feed
$pagefeed = $facebook->api('/' . $pageid . '/feed');



ob_start();
$max_mostrados = 3;
// set counter to 0, because we only want to display 10 posts
$i = 0;

foreach ($pagefeed['data'] as $post) {
    echo '<div class="fb-feed">';

    if ($post['type'] == 'status' || $post['type'] == 'link' || $post['type'] == 'photo') {


        // open up an fb-update div
        // post the time
        // check if post type is a status
        if ($post['type'] == 'status') {
            if (empty($_GET['option'])or ( $_GET['option'] == $post['id'])) {
                echo '<div class="fb-update">';
                echo '<h2>Publicado el: ' . date('j M, Y', (strtotime($post['created_time']))) . '</h2>';
                if (empty($post['story']) === false) {
                    echo '<p>' . $post['story'] . '</p>';
                } elseif (empty($post['message']) === false) {
                    echo '<p>' . $post['message'] . '</p>';
                }
                if (empty($_GET['option'])) {
                    echo "<a class='button' href='fb_news/{$post['id']}'>Leer</a>";
                }

                echo '</div>'; // close fb-update div
            }
        }

        // check if post type is a link
        if ($post['type'] == 'link') {
            /* echo "<h2>Enlace publicado el: " . date("j M, Y", (strtotime($post['created_time']))) . "</h2>";
              echo "<p>" . $post['name'] . "</p>";
              echo "<p><a href=\"" . $post['link'] . "\" target=\"_blank\">" . $post['link'] . "</a></p>"; */
        }

        // check if post type is a photo
        /*  if ($post['type'] == 'photo') {
          echo "<h2>Foto publicada el: " . date("j M, Y", (strtotime($post['created_time']))) . "</h2>";
          if (empty($post['story']) === false) {
          echo "<p>" . $post['story'] . "</p>";
          } elseif (empty($post['message']) === false) {
          echo "<p>" . $post['message'] . "</p>";
          }


          echo "<a href='{$post['link']}'><img src='{$post['picture']}'/></a>";

          }
         */

        echo '</div>'; // close fb-update div

        $i++; // add 1 to the counter if our condition for $post['type'] is met
    }


    //  break out of the loop if counter has reached 10
    if ($i == $max_mostrados) {
        break;
    }
} // end the foreach statement

echo '</div>';

ob_flush();
